package com.yanggu.spark.core.rdd.action

import org.apache.spark.{SparkConf, SparkContext}

//Action算子-Foreach
object RDD35_Foreach {

  def main(args: Array[String]): Unit = {

    //1. 创建sparkConf配置对象
    val sparkConf = new SparkConf().setMaster("local[1]").setAppName("spark")

    //2. 创建spark上下文对象
    val sparkContext = new SparkContext(sparkConf)

    //3. 从内存中创建RDD
    val value = sparkContext.makeRDD(List((1, "a"), (1, "a"), (1, "a"), (2, "b"), (3, "c"), (3, "c")))

    //4. foreach
    //该方法是将分区内的数据进行循环遍历, 所以没有顺序性
    value.foreach {
      case (i, str) => println(s"key: $i, value: $str")
    }

    //6. 释放资源
    sparkContext.stop()
  }

}
